
import { type PaginationProps } from "@pureadmin/table";
import { ElMessage, FormInstance } from "element-plus";
import { ref, reactive, nextTick, watch, onMounted } from "vue";
import {
  InternalRatingModelBaseData, InternalRatingModelList, BuildInternalRatingModel,
  InternalRatingModelDetail, QueryInternalRatingResultChart, IsLooked
} from "@/api/stu/bankBigData";
import { useRoute } from "vue-router";
import qs from "qs";
export function useBuildInternal() {
  const route = useRoute();
  const dataList = ref<any>([]);
  const loading = ref<boolean>(true);
  const CreditVisible = ref<boolean>(false);
  const showVisible = ref<boolean>(false);
  const regex = /^[\u4e00-\u9fa5]{1,20}$/;// 校验2-4个字中文
  const pagination = reactive<PaginationProps>({
    total: 0,
    pageSize: 20,
    currentPage: 1,
    pageSizes: [10, 20, 50, 100],
    background: true
  });
  const formData = reactive({
    modelName: '',
    customerType: '',
  })

  const finanItems = ref([]);

  const competItems = ref([]);

  const creditItems = ref([]);

  const assetItems = ref([]);

  const credit1Items = ref([]);

  const stabilityItems = ref([]);






  const companyList = reactive([{
    level: '',
    industry: [],
    financialIndicatorsList: [],//财务指标数据
    competitiveIndicatorsList: [],//竞争指标数据
    creditIndicatorsList: []//信用指标数据
  }])

  const showData = ref()
  const showType = ref()
  const showTittle = ref()
  const showList = reactive([])
  //公司客户选项数据
  const operationListSelect = reactive([
    {
      "selectId": ">",
      "selectName": ">",
      "selectContent": ">"
    },
    {
      "selectId": "=",
      "selectName": "=",
      "selectContent": "="
    },
    {
      "selectId": "<",
      "selectName": "<",
      "selectContent": "<"
    },
    {
      "selectId": ">=",
      "selectName": ">=",
      "selectContent": ">="
    },
    {
      "selectId": "<=",
      "selectName": "<=",
      "selectContent": "<="
    },
    {
      "selectId": "≠",
      "selectName": "≠",
      "selectContent": "≠"
    },
  ])

  const operationListInput = reactive([
    {
      "selectId": "包含",
      "selectName": "包含",
      "selectContent": "包含"
    },
    {
      "selectId": "不包含",
      "selectName": "不包含",
      "selectContent": "不包含"
    }
  ])

  const companySelectData = reactive({
    levelList: [],
    industyList: [],
    financialIndicatorsSelectList: [],
    competitiveIndicatorsSelectList: [],
    creditIndicatorsSelectList: []
  })
  //零售客户选项数据
  const retailList = reactive([{
    level: '',
    loan: '',
    financialIndicatorsList: [],//财务指标
    competitiveIndicatorsList: [],//竞争指标
    creditIndicatorsList: []//信用指标
  }])
  const retailSelectData = reactive({
    levelList: [],
    loanTypeList: [],
    assetIndexList: [],
    creditIndexList: [],
    stabilityIndexList: []
  })


  const columns: TableColumnList = [
    {
      label: "序号",
      type: "index",
      minWidth: 100
    },
    {
      label: "模型名称",
      prop: "userModelName",
      minWidth: 200
    },
    {
      label: "客户类型",
      prop: "customerType",
      minWidth: 100
    },
    {
      label: "操作",
      fixed: "right",
      width: 200,
      slot: "operation"
    }
  ];

  const BtnLoading = ref<boolean>(false)
  function OUTBtnLoding() {
    setTimeout(() => {
      BtnLoading.value = false
    }, 1000)
  }

  async function ApplyCreditScore() {
    const data = {
      taskId: route.query.taskId,
      planId: route.query.planId,
      module: 1
    }
    let res = await IsLooked(data)
    if (res.data) {
      CreditVisible.value = true;
    } else {
      ElMessage.warning('请先查看客户信息')
    }
  }
  //置空表单
  function CloseVisible() {
    CreditVisible.value = false;
    companySelectData.levelList.forEach(item => item.disabled = false)
    companySelectData.competitiveIndicatorsSelectList.fieldData.forEach(item => {
      item.selectOption.forEach(a => a.disabled = false)
    })
    companySelectData.creditIndicatorsSelectList.fieldData.forEach(item => {
      item.selectOption.forEach(a => a.disabled = false)
    })
    companySelectData.financialIndicatorsSelectList.fieldData.forEach(item => {
      item.selectOption.forEach(a => a.disabled = false)
    })
    retailSelectData.levelList.forEach(item => item.disabled = false)
    retailSelectData.assetIndexList.fieldData.forEach(item => {
      item.selectOption.forEach(a => a.disabled = false)
    })
    retailSelectData.creditIndexList.fieldData.forEach(item => {
      item.selectOption.forEach(a => a.disabled = false)
    })
    retailSelectData.stabilityIndexList.fieldData.forEach(item => {
      item.selectOption.forEach(a => a.disabled = false)
    })
    companyList.splice(0, companyList.length); // 清空数组
    // 添加初始值
    companyList.push({
      level: '',
      industry: [],
      financialIndicatorsList: [],
      competitiveIndicatorsList: [],
      creditIndicatorsList: []
    });
    retailList.splice(0, retailList.length); // 清空数组
    // 添加初始值
    retailList.push({
      level: '',
      loan: '',
      financialIndicatorsList: [],//财务指标
      competitiveIndicatorsList: [],//竞争指标
      creditIndicatorsList: []//信用指标
    });
    formData.customerType = ''
    formData.modelName = ''
    finanItems.value = []
    creditItems.value = []
    assetItems.value = []
    competItems.value = []
    credit1Items.value = []
    stabilityItems.value = []
  };

  // 确定
  async function SubmitVisible() {
    console.log(regex.test(formData.modelName));

    if (regex.test(formData.modelName) === false) {
      ElMessage.warning('模型名称应输入1-20个汉字')
      return
    }
    if (formData.customerType === '' || !formData.customerType) {
      ElMessage.warning('请选择客户类型')
      return
    }
    const data = {
      planId: route.query.planId,
      taskId: route.query.taskId,
      customerType: 'CompanyCustomers',
      userModelName: formData.modelName,
    }
    if (formData.customerType === 'CompanyCustomers') {
      let stopExecution = true
      companyList.forEach((item, index) => {
        if (item.level == '' || !item.level) {
          stopExecution = false
          ElMessage.warning(`第${index + 1}个评分模型未选择等级`)
          return
        }
        if (item.financialIndicatorsList.length == 0 && item.competitiveIndicatorsList.length == 0 && item.creditIndicatorsList.length == 0) {
          stopExecution = false
          ElMessage.warning(`第${index + 1}个评分模型至少填写一个指标`)
          return
        }
      })
      if (stopExecution) {
        const internalRatingModelGradeList = [];
        const pushItem = (item, field) => {
          item[field].forEach(a => {
            internalRatingModelGradeList.push({
              remark: a.remark,
              ModelCode: a.modelCode,
              ModuleCode: 'CompanyCustomers',
              FieldName: a.dataField,
              OperatorStr: a.confirmSelect,
              EvaluationGrade: item.level,
              ParameterValue: Array.isArray(a.confirmSelectValue) ? a.confirmSelectValue.join(',') : a.confirmSelectValue,
              industrys: item.industry.join('|'),
              loanType: '',
              dataSetType: a.dataSetType
            });
          });
        };
        companyList.forEach(item => {
          pushItem(item, 'competitiveIndicatorsList');
          pushItem(item, 'creditIndicatorsList');
          pushItem(item, 'financialIndicatorsList');
        });
        data.internalRatingModelGradeList = internalRatingModelGradeList;
        data.studentAnswer = JSON.stringify(data);
        const res = await BuildInternalRatingModel(data);
        if (res.success) {
          ElMessage.success(res.msg)
          CloseVisible()
          getList()
        } else {
          ElMessage.error(res.msg)
        }
      }
    } else {
      data.customerType = 'RetailCustomers'
      let stopExecution = true
      retailList.forEach((item, index) => {
        if (item.level == '' || !item.level) {
          stopExecution = false
          ElMessage.warning(`第${index + 1}个评分模型未选择等级`)
          return
        }
        if (item.financialIndicatorsList.length == 0 && item.competitiveIndicatorsList.length == 0 && item.creditIndicatorsList.length == 0) {
          stopExecution = false
          ElMessage.warning(`第${index + 1}个评分模型至少填写一个指标`)
          return
        }
      })
      if (stopExecution) {
        const internalRatingModelGradeList = [];
        const pushItem = (item, field) => {
          item[field].forEach(a => {
            console.log(item.loan);

            internalRatingModelGradeList.push({
              remark: a.remark,
              ModelCode: a.modelCode,
              ModuleCode: 'RetailCustomers',
              FieldName: a.dataField,
              OperatorStr: a.confirmSelect,
              EvaluationGrade: item.level,
              ParameterValue: Array.isArray(a.confirmSelectValue) ? a.confirmSelectValue.join(',') : a.confirmSelectValue,
              loanType: item.loan,
              industrys: '',
              dataSetType: a.dataSetType
            });
          });
        };
        retailList.forEach(item => {
          pushItem(item, 'competitiveIndicatorsList');
          pushItem(item, 'creditIndicatorsList');
          pushItem(item, 'financialIndicatorsList');
        });
        data.internalRatingModelGradeList = internalRatingModelGradeList;
        data.studentAnswer = JSON.stringify(data);
        const res = await BuildInternalRatingModel(data);
        if (res.success) {
          ElMessage.success(res.msg)
          CloseVisible()
          getList()
        } else {
          ElMessage.error(res.msg)
        }
      }
    }
    BtnLoading.value = true;
    OUTBtnLoding()
  }

  function handleSizeChange() {
    getList()
  }

  function handleCurrentChange() {
    getList()
  }


  async function getList() {
    const data = {
      pageIndex: pagination.currentPage,
      pageCount: pagination.pageSize,
      planId: route.query.planId,
      taskId: route.query.taskId,
    }
    const res = await InternalRatingModelList(data);
    if (res.success) {
      res.data?.items.forEach(item => {
        item.createTime = item.createTime.substring(0, 10)
      })
      pagination.total = res.data.totalCount;
      dataList.value = res.data.items;
      loading.value = false;
    } else {
      ElMessage.error(res.msg);
      setTimeout(() => {
        loading.value = false;
      }, 1500)
    }
  }
  //添加公司客户财务指标
  function changeSelectCompanyFinan(t, item, index) {
    console.log(index);

    if (item.level == '') {
      ElMessage.warning('请先选择评级等级')
      finanItems.value[index] = []
      return
    }
    const arr = companyList.filter(a => a.level == item.level)[0].financialIndicatorsList
    for (let i = 0; i < arr.length; i++) {
      if (arr[i].apiFieldInfoId == t.apiFieldInfoId) {
        arr.splice(i, 1); // 删除已有项
        return;
      }
    }
    arr.push({
      modelCode: "FinancialIndex",
      apiFieldInfoId: t.apiFieldInfoId,
      dataField: t.dataField,
      remark: t.remark,
      selection: t.selectOption,
      filedType: t.fieldType,
      dataSetType: t.dataSetType,
      confirmSelect: '',
      confirmSelectValue: ''
    })
  }
  //添加公司客户竞争指标
  function changeSelectCompanyCompet(t, item, index) {
    console.log(t);

    if (item.level == '') {
      ElMessage.warning('请先选择评级等级')
      competItems.value[index] = []
      return
    }
    const arr = companyList.filter(a => a.level == item.level)[0].competitiveIndicatorsList
    for (let i = 0; i < arr.length; i++) {
      if (arr[i].apiFieldInfoId == t.apiFieldInfoId) {
        arr.splice(i, 1); // 删除已有项
        return;
      }
    }
    arr.push({
      modelCode: "CompetitiveIndex",
      dataField: t.dataField,
      apiFieldInfoId: t.apiFieldInfoId,
      remark: t.remark,
      selection: t.selectOption,
      filedType: t.fieldType,
      dataSetType: t.dataSetType,
      confirmSelect: '',
      confirmSelectValue: ''
    })
    console.log(arr);

  }
  //添加公司客户信用指标
  function changeSelectCompanyCredit(t, item, index) {
    console.log(t);

    if (item.level == '') {
      ElMessage.warning('请先选择评级等级')
      creditItems.value[index] = []
      return
    }
    const arr = companyList.filter(a => a.level == item.level)[0].creditIndicatorsList
    for (let i = 0; i < arr.length; i++) {
      if (arr[i].apiFieldInfoId == t.apiFieldInfoId) {
        arr.splice(i, 1); // 删除已有项
        return;
      }
    }
    arr.push({
      modelCode: "CreditMetricsIndex",
      apiFieldInfoId: t.apiFieldInfoId,
      dataField: t.dataField,
      remark: t.remark,
      selection: t.selectOption,
      filedType: t.fieldType,
      dataSetType: t.dataSetType,
      confirmSelect: '',
      confirmSelectValue: ''
    })
  }

  //添➕零售客户资产指标
  function changeSelectRetailFinan(t, item, index) {
    if (item.level == '') {
      ElMessage.warning('请先选择评级等级')
      assetItems.value[index] = []
      return
    }
    const arr = retailList.filter(a => a.level == item.level)[0].financialIndicatorsList
    for (let i = 0; i < arr.length; i++) {
      if (arr[i].apiFieldInfoId == t.apiFieldInfoId) {
        arr.splice(i, 1); // 删除已有项
        return;
      }
    }
    arr.push({
      modelCode: "AssetIndex",
      apiFieldInfoId: t.apiFieldInfoId,
      dataField: t.dataField,
      remark: t.remark,
      selection: t.selectOption,
      filedType: t.fieldType,
      dataSetType: t.dataSetType,
      confirmSelect: '',
      confirmSelectValue: ''
    })
  }
  //添加零售客户征信
  function changeSelectRetailCompet(t, item, index) {
    console.log(t);

    if (item.level == '') {
      ElMessage.warning('请先选择评级等级')
      credit1Items.value[index] = []
      return
    }
    const arr = retailList.filter(a => a.level == item.level)[0].competitiveIndicatorsList
    for (let i = 0; i < arr.length; i++) {
      if (arr[i].apiFieldInfoId == t.apiFieldInfoId) {
        arr.splice(i, 1); // 删除已有项
        return;
      }
    }
    arr.push({
      modelCode: "CreditIndex",
      dataField: t.dataField,
      apiFieldInfoId: t.apiFieldInfoId,
      remark: t.remark,
      selection: t.selectOption,
      filedType: t.fieldType,
      dataSetType: t.dataSetType,
      confirmSelect: '',
      confirmSelectValue: ''
    })
  }
  //添加零售客户稳定性指标
  function changeSelectRetailCredit(t, item, index) {
    if (item.level == '') {
      ElMessage.warning('请先选择评级等级')
      stabilityItems.value[index] = []
      return
    }
    const arr = retailList.filter(a => a.level == item.level)[0].creditIndicatorsList
    for (let i = 0; i < arr.length; i++) {
      if (arr[i].apiFieldInfoId == t.apiFieldInfoId) {
        arr.splice(i, 1); // 删除已有项
        return;
      }
    }
    arr.push({
      modelCode: "StabilityIndex",
      apiFieldInfoId: t.apiFieldInfoId,
      dataField: t.dataField,
      remark: t.remark,
      selection: t.selectOption,
      filedType: t.fieldType,
      dataSetType: t.dataSetType,
      confirmSelect: '',
      confirmSelectValue: ''
    })
  }
  //添加公司评级等级
  function addLevel() {
    companyList.push({
      level: '',
      industry: [],
      financialIndicatorsList: [],
      competitiveIndicatorsList: [],
      creditIndicatorsList: []
    })
    finanItems.value.push([])
    competItems.value.push([])
    creditItems.value.push([])
  }

  function deleteCompany() {
    if (companyList.length == 1) {
      ElMessage.warning('至少保留一个评级等级')
    } else {
      finanItems.value.pop()
      competItems.value.pop()
      creditItems.value.pop()
      let arr = companyList[companyList.length - 1].level
      companySelectData.levelList.forEach(item => {
        if (item.selectId == arr) {
          item.disabled = false
        }
      })
      companyList.pop() //删除一个
    }
  }
  //添加零售等级
  function addLevel1() {
    retailList.push({
      level: '',
      loan: '',
      financialIndicatorsList: [],//财务指标
      competitiveIndicatorsList: [],//竞争指标
      creditIndicatorsList: []//信用指标
    })
    assetItems.value.push([])
    credit1Items.value.push([])
    stabilityItems.value.push([])
  }


  function deleteRetail() {
    if (retailList.length == 1) {
      ElMessage.warning('至少保留一个评级等级')
    } else {
      assetItems.value.pop()
      credit1Items.value.pop()
      stabilityItems.value.pop()
      let arr = retailList[retailList.length - 1].level
      retailSelectData.levelList.forEach(item => {
        if (item.selectId == arr) {
          item.disabled = false
        }
      })
      retailList.pop()
    }
  }
  //联动禁止单选
  // function updateSelectors(select, code, id) {
  //   //后续优化为选择时禁用其顶层元素

  //   if (code == 'CompetitiveIndex') {
  //     companySelectData.competitiveIndicatorsSelectList.fieldData.forEach(item => {
  //       if (item.apiFieldInfoId == id) {
  //         item.selectOption.forEach(el => {
  //           if (el.selectId == select) {
  //             el.disabled = true
  //           }
  //         })
  //       }
  //     })
  //   }

  //   if (code == 'FinancialIndex') {
  //     companySelectData.financialIndicatorsSelectList.fieldData.forEach(item => {
  //       if (item.apiFieldInfoId == id) {
  //         item.selectOption.forEach(el => {
  //           if (el.selectId == select) {
  //             el.disabled = true
  //           }
  //         })
  //       }
  //     })
  //   }

  //   if (code == 'CreditMetricsIndex') {
  //     companySelectData.creditIndicatorsSelectList.fieldData.forEach(item => {
  //       if (item.apiFieldInfoId == id) {
  //         item.selectOption.forEach(el => {
  //           if (el.selectId == select) {
  //             el.disabled = true
  //           }
  //         })
  //       }
  //     })
  //   }

  //   if (code == 'AssetIndex') {
  //     retailSelectData.assetIndexList.fieldData.forEach(item => {
  //       if (item.apiFieldInfoId == id) {
  //         item.selectOption.forEach(el => {
  //           if (el.selectId == select) {
  //             el.disabled = true
  //           }
  //         })
  //       }
  //     })
  //   }
  //   if (code == 'CreditIndex') {
  //     retailSelectData.creditIndexList.fieldData.forEach(item => {
  //       if (item.apiFieldInfoId == id) {
  //         item.selectOption.forEach(el => {
  //           if (el.selectId == select) {
  //             el.disabled = true
  //           }
  //         })
  //       }
  //     })
  //   }
  //   if (code == 'StabilityIndex') {
  //     retailSelectData.stabilityIndexList.fieldData.forEach(item => {
  //       if (item.apiFieldInfoId == id) {
  //         item.selectOption.forEach(el => {
  //           if (el.selectId == select) {
  //             el.disabled = true
  //           }
  //         })
  //       }
  //     })
  //   }
  // }
  //联动处理等级更换
  function updateLevelSelect(select, type) {
    if (type == 'company') {
      let selectArr = companyList.map(item => item.level)
      companySelectData.levelList.forEach(b => {
        if (selectArr.includes(b.selectId)) {
          b.disabled = true
        } else {
          b.disabled = false
        }
      })
      return
    }
    if (type == 'retail') {
      let selectArr = retailList.map(item => item.level)
      retailSelectData.levelList.forEach(b => {
        if (selectArr.includes(b.selectId)) {
          b.disabled = true
        } else {
          b.disabled = false
        }
      })
    }
  }
  //处理新建模型数据
  async function handleCreatedModelData() {
    const data = {
      planId: route.query.planId,
      taskId: route.query.taskId,
    }
    let res = await InternalRatingModelBaseData(data)
    if (res.success) {
      res?.data.companyData.gradeList.forEach(item => {
        item.disabled = false
      })
      companySelectData.levelList = res?.data.companyData.gradeList
      companySelectData.industyList = res?.data.companyData.industryList
      res?.data.companyData.fieldInfoData.filter(item => item.modelCode == 'FinancialIndex')[0].fieldData.forEach(item => {
        item.disabled = false
      })
      res?.data.companyData.fieldInfoData.filter(item => item.modelCode == 'CompetitiveIndex')[0].fieldData.forEach(item => {
        item.selectOption.forEach(el => {
          el.disabled = false
        })
      })
      res?.data.companyData.fieldInfoData.filter(item => item.modelCode == 'CreditMetricsIndex')[0].fieldData.forEach(item => {
        item.selectOption.forEach(el => {
          el.disabled = false
        })
      })
      companySelectData.financialIndicatorsSelectList = res?.data.companyData.fieldInfoData.filter(item => item.modelCode == 'FinancialIndex')[0]
      companySelectData.competitiveIndicatorsSelectList = res?.data.companyData.fieldInfoData.filter(item => item.modelCode == 'CompetitiveIndex')[0]
      companySelectData.creditIndicatorsSelectList = res?.data.companyData.fieldInfoData.filter(item => item.modelCode == 'CreditMetricsIndex')[0]
      //零售客户
      res?.data.retailData.gradeList.forEach(item => {
        item.disabled = false
      })
      res?.data.retailData.fieldInfoData.filter(item => item.modelCode == 'AssetIndex')[0].fieldData.forEach(item => {
        item.disabled = false
      })
      res?.data.retailData.fieldInfoData.filter(item => item.modelCode == 'CreditIndex')[0].fieldData.forEach(item => {
        item.selectOption.forEach(el => {
          el.disabled = false
        })
      })
      res?.data.retailData.fieldInfoData.filter(item => item.modelCode == 'StabilityIndex')[0].fieldData.forEach(item => {
        item.selectOption.forEach(el => {
          el.disabled = false
        })
      })
      retailSelectData.levelList = res?.data.retailData.gradeList
      retailSelectData.loanTypeList = res?.data.retailData.loanTypeList
      retailSelectData.assetIndexList = res?.data.retailData.fieldInfoData.filter(item => item.modelCode == 'AssetIndex')[0]
      retailSelectData.creditIndexList = res?.data.retailData.fieldInfoData.filter(item => item.modelCode == 'CreditIndex')[0]
      retailSelectData.stabilityIndexList = res?.data.retailData.fieldInfoData.filter(item => item.modelCode == 'StabilityIndex')[0]
    } else {
      ElMessage.error(res.msg);
    }

  }

  //展示详情
  async function ShowReportDestail(row) {
    showList.splice(0, showList.length);
    const data = {
      planId: route.query.planId,
      taskId: route.query.taskId,
      detailId: row.internalRatingModelId
    }
    let res = await InternalRatingModelDetail(data)
    showType.value = res?.data.customerType
    showTittle.value = res?.data.userModelName
    if (res?.data.customerType == 'CompanyCustomers') {
      res?.data.internalRatingModelGradeList.forEach(item => {
        const {
          evaluationGrade,
          operatorStr,
          fieldName,
          remark,
          parameterValue,
          modelCode,
          moduleCode,
          loanType,
          industrys
        } = item
        const newItem = {
          level: evaluationGrade,
          industry: '',
          financialIndicatorsList: [],
          competitiveIndicatorsList: [],
          creditIndicatorsList: []
        };
        let targetItem = showList.find(a => a.level === evaluationGrade);
        if (!targetItem) {
          targetItem = { ...newItem };
          showList.push(targetItem);
        }
        const {
          financialIndicatorsList,
          competitiveIndicatorsList,
          creditIndicatorsList
        } = targetItem;
        const newItemData = {
          code: modelCode,
          fieldName: fieldName,
          operatorStr: operatorStr,
          parameterValue: parameterValue,
          remark: remark,
        };
        if (modelCode === 'FinancialIndex') {
          financialIndicatorsList.push(newItemData);
        } else if (modelCode === 'CompetitiveIndex') {
          competitiveIndicatorsList.push(newItemData);
        } else if (modelCode === 'CreditMetricsIndex') {
          creditIndicatorsList.push(newItemData);
        }
        targetItem.industry = industrys
        console.log(showList);
      })
    } else {
      res?.data.internalRatingModelGradeList.forEach(item => {
        const {
          evaluationGrade,
          operatorStr,
          fieldName,
          remark,
          parameterValue,
          modelCode,
          moduleCode,
          loanType,
          industrys
        } = item
        const newItem = {
          level: evaluationGrade,
          loanType: '',
          credit1List: [],
          stabilityList: [],
          assetList: []
        };
        let targetItem = showList.find(a => a.level === evaluationGrade);
        if (!targetItem) {
          targetItem = { ...newItem };
          showList.push(targetItem);
        }
        const {
          credit1List,
          stabilityList,
          assetList
        } = targetItem;
        const newItemData = {
          code: modelCode,
          fieldName: fieldName,
          operatorStr: operatorStr,
          parameterValue: parameterValue,
          remark: remark,
        };
        if (modelCode === 'CreditIndex') {
          credit1List.push(newItemData);
        } else if (modelCode === 'StabilityIndex') {
          stabilityList.push(newItemData);
        } else if (modelCode === 'AssetIndex') {
          assetList.push(newItemData);
        }
        targetItem.loanType = loanType
      })
    }
    showVisible.value = true
  }
  onMounted(async () => {
    handleCreatedModelData()
    getList()
  })

  return {
    dataList,
    loading,
    CreditVisible,
    pagination,
    columns,
    formData,
    handleCurrentChange,
    handleSizeChange,
    ApplyCreditScore,
    SubmitVisible,
    CloseVisible,
    companyList,
    retailList,
    BtnLoading,
    companySelectData,
    retailSelectData,
    operationListInput,
    operationListSelect,
    changeSelectCompanyFinan,
    changeSelectCompanyCompet,
    changeSelectCompanyCredit,
    changeSelectRetailFinan,
    changeSelectRetailCompet,
    changeSelectRetailCredit,
    addLevel,
    finanItems,
    competItems,
    creditItems,
    assetItems,
    credit1Items,
    stabilityItems,
    // updateSelectors,
    updateLevelSelect,
    addLevel1,
    ShowReportDestail,
    showList,
    showType,
    showTittle,
    showVisible,
    deleteCompany,
    deleteRetail
  }
}
